package cn.itcast.demo.controller;

import cn.itcast.demo.pojo.User;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

/**
 * @Author: taft
 * @Date: 2018-10-21 10:34
 */
@Controller
@RequestMapping("heima43")
public class HelloController {


    @GetMapping("show1")
    public String hello(Model model){
        model.addAttribute("msg","hello heima43");
        return "show1";
    }

    @GetMapping("show2")
    public String sayHello1(Model model){

        User user = new User();
        user.setName("ldh");
        user.setAge(50);

        User freid = new User();
        freid.setAge(55);
        freid.setName("zxy");


        user.setFriend(freid);

        model.addAttribute("user",user);
        return "show2";
    }


    @GetMapping("show3")
    public String sayHello2(Model model){

        User user = new User();
        user.setName("l d h");
        user.setAge(50);

        User freid = new User();
        freid.setAge(55);
        freid.setName("z x y");


        user.setFriend(freid);

        model.addAttribute("user",user);
        return "show3";
    }

    @GetMapping("show4")
    public String sayHello3(Model model){



        model.addAttribute("date",new Date());

        model.addAttribute("name","zzh");

        return "show4";
    }


    @GetMapping("show5")
    public String sayHello4(Model model){

        User user1 = new User("ldh",50,null);
        User user2 = new User("zxy",55,null);
        User user3 = new User("lm",45,null);
        User user4 = new User("gtl",38,null);

        List<User> users = new ArrayList<>();

        users.add(user1);
        users.add(user2);
        users.add(user3);
        users.add(user4);




        model.addAttribute("users",users);

        return "show5";
    }


    @GetMapping("show6")
    public String sayHello5(Model model){

        User user1 = new User("ldh",50,null);



        model.addAttribute("user",user1);

        return "show6";
    }
}
